package cn.bgs.controller;


import cn.bgs.common.AliOss;
import cn.bgs.common.R;
import cn.bgs.pojo.File;
import cn.bgs.pojo.vo.VehicleCarVo;
import cn.bgs.service.IFileService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 * 文件表 前端控制器
 * </p>
 *
 * @author cf
 * @since 2022-06-07
 */
@RestController
@RequestMapping("/file")
public class FileController {

    @Autowired
    private AliOss aliOss;

    @Autowired
    private IFileService fileService;

    int id;

    @RequestMapping("/upload")
    @ApiOperation(value = "app我的房屋(住户信息的身份证正面照片)")
    public String upload(MultipartFile file){

       String file1=aliOss.upload(file);
        System.out.println(file1);

        return file1;
    }

    @ApiOperation(value = "app我的车辆(车身图片)")
    @RequestMapping("/addCarBody/{vehicleCarId}")
    public void addCarBody(@PathVariable("vehicleCarId") Integer vehicleCarId){
        id = vehicleCarId;
        System.out.println("============="+vehicleCarId);
    };
    @PostMapping("/addCarPhoto")
    public void addCarPhoto(@RequestBody VehicleCarVo VehicleCarVo){
        fileService.addCarPhoto(id,VehicleCarVo.getFileUrl());
    }

    @PostMapping("/getCarPhoto/{vehicleCarId}")
    public R getCarPhoto(@PathVariable Integer vehicleCarId){
        File file = fileService.getCarPhoto(vehicleCarId);
        return R.ok().data("file",file);
    }

    @PostMapping("/updCarPhoto")
    public R updCarPhoto(@RequestBody File file) {
        int upd = fileService.updCarPhoto(file);
        if (upd == 1) {
            return R.ok();
        } else {
            return R.error();
        }
    }
}
